<template>
  <div>加载中...</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router'
import { useLoginUserState } from '@/stores/useLoginUserState.ts'
import { getCurrentUserSpaceUsingGet } from '@/api/spaceController.ts'
import { message } from 'ant-design-vue'
import { onMounted } from 'vue'

const router = useRouter()
const loginUserState = useLoginUserState()
const checkUserSpace = async () => {
  const loginUser = loginUserState.loginUser
  if (!loginUser?.id) {
    router.replace('/user/login')
    return
  }
  // 查询当前登录用户的space信息
  const res = await getCurrentUserSpaceUsingGet()
  if (res.data) {
    router.replace(`/space/${res.data.id}`)
  } else {
    router.replace('/add_space')
    message.warning('请先创建自己的空间')
  }
}

onMounted(() => {
  checkUserSpace()
})
</script>

<style scoped></style>
